package leetcode;

public class 整数反转 {

    public static int reverse(int x) {
        int sum = 0;
        // res<-214748364 || (res==-214748364
        while (x != 0) {
            int temp = x%10;

            if(sum > 214748364 || sum < -214748364) {
                return 0;
            }
            System.out.println(temp);
            sum = sum*10 + temp;
            x /= 10;
        }
        return  sum;
    }

    public static void main(String[] args) {
       int x = -123;
        int reverse = reverse(x);
        System.out.println(reverse);
        System.out.println(x%10);
    }
}
